package au.com.iglootech.TaxTimeToolTip.ui.feerate;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import au.com.iglootech.TaxTimeToolTip.Entity.Company;
import au.com.iglootech.TaxTimeToolTip.Entity.FeeRate;
import au.com.iglootech.TaxTimeToolTip.dao.GenericDao;
import au.com.iglootech.TaxTimeToolTip.ui.fillupform.FillUpTimeSheetTab;
import au.com.iglootech.TaxTimeToolTip.ui.fillupform.TodayTimeSheetTab;

import com.vaadin.data.util.BeanContainer;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Panel;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.Table;
import com.vaadin.ui.VerticalLayout;
@Configurable(preConstruction=true)
@Component
@Scope("request")
public class ShowFeeRateTab extends CustomComponent {
	VerticalLayout mainLayout = new VerticalLayout();
	@Autowired
	private transient GenericDao genericDao;
	private BeanContainer<String, FeeRate> beans;
	private Table feeRateTable;

	public ShowFeeRateTab() {
		this.setCaption("Fee Rate");
		initContent();
	}

	private void initContent() {
		Panel panel = new Panel();
		beans = new BeanContainer<String, FeeRate>(
				FeeRate.class);

		// Use the name property as the item ID of the bean
		List<FeeRate> feeRates = new ArrayList<FeeRate>(genericDao.findAll(FeeRate.class));
		beans.setBeanIdProperty("key");
		for(FeeRate feeRate : feeRates)
		{
			beans.addBean(feeRate);
		}

		feeRateTable = new Table("Fee Rate List", beans);
		feeRateTable.setVisibleColumns(new String[]{"rate"});
		feeRateTable.setRowHeaderMode(Table.ROW_HEADER_MODE_INDEX);
		panel.addComponent(feeRateTable);
		mainLayout.addComponent(panel);
		this.setCompositionRoot(mainLayout);
	}
	
	public void refresh()
	{
		List<FeeRate> feeRates = new ArrayList<FeeRate>(genericDao.findAll(FeeRate.class));
		beans.removeAllItems();
		for(FeeRate feeRate : feeRates)
		{
			beans.addBean(feeRate);
		}
	}
}
